package zoo.product.controller;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import zoo.order.domain.OrderCommand;
import zoo.product.dao.ProductDao;
import zoo.product.domain.HitCommand;
import zoo.product.validator.ProductValidator;

@Controller
public class ProductBestContoroller {

	@Autowired
	private ProductDao productDao;
	
	@ModelAttribute("hit")
	public HitCommand formBacking() {
		return new HitCommand();
	}
		
	@RequestMapping(value="/main/detailBest.do")
	public ModelAndView process(@RequestParam("p_code")int p_code,
						  @RequestParam("userid")String userid				  
						  ){
		String formView = "redirect:/main/detailPro.do?p_code="+p_code;
		
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("p_code", p_code);
		map.put("userid", userid);
				
		String search = productDao.hitSearch(map);
						
		if(search == null){
			productDao.updateHitBest(map);
			productDao.updateProBest(p_code);
		}else if(search != null){
			
			return new ModelAndView(formView,"sc",search);
		}
		
		return new ModelAndView(formView,"sc",search);
	}
}
